<template>
  <div class="app-container">
    <avue-crud
      :option="option"
      :data="data"
      :table-loading="loading"
      :page.sync="page"
      @on-load="onLoad"
      @current-change="currentChange"
      @size-change="pageSizeChange"
      @search-change="searchChange"
      @search-reset="resetChange"
    >
    </avue-crud>
  </div>
</template>

<script>
import { getLog } from '@/api/user.js'
export default {
  data() {
    return {
      loading: false,
      /* 分页 */
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      data: [],
      searchList: {},
      option: {
        headerAlign: 'center',
        align: 'center',
        border: true,
        index: true,
        indexLabel: '序号',
        indexWidth: 100,
        card: true,
        defaultExpandAll: true,
        editBtn: false,
        addBtn: false,
        delBtn: false,
        dialogDrag: false,
        menu: false,
        //height: 600,
        searchMenuSpan: 4,
        searchSpan: 6,
        searchLabelWidth: '25%',
        column: [
          {
            label: '操作模块',
            prop: 'opModule',
            fixed: true,
          },
          {
            label: '操作类型',
            prop: 'opType',
            fixed: true,
            overHidden: true,
            search: true,
          },
          {
            label: '终端地址',
            prop: 'clientIp',
            overHidden: true,
          },
          {
            label: '操作时间',
            prop: 'opTime',
            type: 'date',
            search: true,
            valueFormat: 'yyyy-MM-dd',
            overHidden: true,
          },
          {
            label: '代理地址',
            prop: 'agentIp',
            overHidden: true,
            hide: true,
          },
          {
            label: '资源地址',
            prop: 'resUrl',
            overHidden: true,
          },
          {
            label: '跳转地址',
            prop: 'refUrl',
            overHidden: true,
          },
          {
            label: '创建人',
            prop: 'cuser',
            overHidden: true,
          },
          {
            label: '执行时间(ms)',
            prop: 'execTime',
          },
          {
            label: '执行结果',
            prop: 'status',
            type: 'select',
            search: true,
            dicData: [
              {
                label: '成功',
                value: true,
              },
              {
                label: '失败',
                value: false,
              },
            ],
          },
          {
            label: '日志详情',
            prop: 'opDesc',
            overHidden: true,
          },
          {
            label: '终端类型',
            prop: 'clientType',
            width: 85,
            hide: true,
          },
        ],
      },
    }
  },
  methods: {
    onLoad(page, params = {}) {
      /* if (page.layout) {
                    Object.assign(params, {
                        page: page.currentPage,
                        size: page.pageSize,
                    });
                } else {
                    Object.assign(params, page);
                } */
      let searchList = this.searchList
      Object.assign(params, {
        ...searchList,
        text: searchList.opType || '',
        source: searchList.opTime || '',
        d: searchList.status == undefined ? '' : searchList.status ? 1 : 0,
        page: this.page.currentPage,
        size: this.page.pageSize,
      })
      this.loading = true
      getLog(params).then((data) => {
        if (data.status) {
          this.loading = false
          this.data = data.data.records
          this.page.total = data.data.total
        } else {
          this.$message.error(data.msg)
        }
      })
    },
    /* 改变页码 */
    currentChange(currentPage) {
      this.page.currentPage = currentPage
    },
    pageSizeChange(pageSize) {
      this.page.pageSize = pageSize
    },
    /* 清空 */
    resetChange() {
      this.page.currentPage = 1
      this.page.pageSize = 10
      this.searchList = {}
      this.onLoad()
    },
    /* 搜索筛选 */
    searchChange(params, done) {
      done()
      this.page.currentPage = 1
      this.page.pageSize = 10
      this.searchList = {
        ...params,
      }
      this.onLoad()
    },
  },
}
</script>

<style lang="scss" scoped="scoped">
/deep/ .avue-crud__pagination {
  text-align: center;
}
</style>
